package com.binguo.model.mybatis;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class DomainExample<T> {
	private T domain;
	
	// 2018-07-09 修改为Collection
	private Collection<String> columns;
	private String orderByClause;

	private boolean distinct;

	private List<Criteria> oredCriteria;
    
	private StdDomain addition; 

	public DomainExample(T domain) {
        oredCriteria = new ArrayList<Criteria>();
        this.domain = domain;
    }

    public void setOrderByClause(String orderByClause) {
        this.orderByClause = orderByClause;
    }

    public String getOrderByClause() {
        return orderByClause;
    }

    public void setDistinct(boolean distinct) {
        this.distinct = distinct;
    }

    public boolean isDistinct() {
        return distinct;
    }

    public List<Criteria> getOredCriteria() {
        return oredCriteria;
    }

    public void or(Criteria criteria) {
        oredCriteria.add(criteria);
    }

    public Criteria or() {
        Criteria criteria = createCriteriaInternal();
        oredCriteria.add(criteria);
        return criteria;
    }

    public Criteria createCriteria() {
        Criteria criteria = createCriteriaInternal();
        if (oredCriteria.size() == 0) {
            oredCriteria.add(criteria);
        }
        return criteria;
    }
    
    public StdDomain createAddition() {
    	if(this.addition == null)
    		this.addition = new StdDomain();
    	
    	return this.addition;
    }

    protected Criteria createCriteriaInternal() {
        Criteria criteria = new Criteria();
        return criteria;
    }

    public void clear() {
        oredCriteria.clear();
        orderByClause = null;
        distinct = false;
    }

	public T getDomain() {
		return domain;
	}

	public void setDomain(T domain) {
		this.domain = domain;
	}

	public Collection<String> getColumns() {
		return columns;
	}

	/**
	 * 设置列名,以domain的列名为准,数据库列名自动转换为下划线
	 * @param columns
	 */
	public void setColumns(String columns) {
		this.columns = Arrays.asList(columns.split(","));
	}
	
	public void setColumns(Collection<String> columns) {
		this.columns = columns;
	}

	public StdDomain getAddition() {
		return addition;
	}

	public void setAddition(StdDomain addition) {
		this.addition = addition;
	}
    
}